{include file="./public/header" title="后台首页"/}
<body class="hold-transition skin-blue fixed sidebar-mini">
<div class="wrapper">

    {include file="./public/navi"/}
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>&nbsp;系统后台</a></li>
                <li class="active">首页</li>
            </ol>
        </section>
        <section class="content">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="box-title">数据备份</div>
                    <div class="box-tools">
                        <button onclick="javascript:location.reload();" type="button"
                                class="btn btn-box-tool"><i class="fa fa-refresh"></i> 刷新
                        </button>
                        <a id="backup-btn" class="btn btn-box-tool delete-all" href="javascript:void(0);"
                           data-url="{:url('admin/database/backup')}" data-title="备份数据库">
                            <i class="fa fa-save"></i> 备份数据库
                        </a>
                        <a id="export" type="button" class="btn btn-box-tool"><i
                                class="fa fa-plus"></i> 备份
                        </a>
                        <a id="optimize" type="button" class="btn btn-box-tool"><i
                                class="fa fa-pencil"></i> 优化
                        </a>
                        <a id="repair" type="button" class="btn btn-box-tool"><i
                                class="fa fa-trash-o fa-fw"></i> 修复
                        </a>

                        <!--  <a id="export" class="btn btn-success" href="javascript:;" autocomplete="off">立即备份</a>
                          <a id="optimize" class="btn btn-success" href="{:url('optimize')}">优化表</a>
                          <a id="repair" class="btn btn-success" href="{:url('repair')}">修复表</a>-->
                    </div>
                </div>
                <div class="box-body table-responsive">

                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="{:url('admin/database/index')}">数据备份</a></li>
                            <li class=""><a href="{:url('admin/database/restore')}">数据恢复</a></li>
                        </ul>
                    </div>
                    <table class="table table-condensed table-striped table-hover table-bordered">
                        <thead>
                        <tr>
                            <th class="text-center">
                                <input class="minimal checkbox-toggle" type="checkbox" value="" checked>
                            </th>
                            <th>表名</th>
                            <th>类型</th>
                            <th>编码</th>
                            <th>记录数</th>
                            <th>大小</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="table"}
                        <tr>
                            <td align="center">
                                <input class="minimal" type="checkbox" name="id[]" value="{$table.Name}" checked>
                            </td>
                            <td>{$table.Name}</td>
                            <td>{$table.Engine}</td>
                            <td>{$table.Collation}</td>
                            <td>{$table.Rows}</td>
                            <td>{$table.Data_length|format_bytes}</td>
                            <td>{$table.Comment}</td>
                            <td class="action">
                                <a class="ajax-get no-refresh"
                                   href="{:url('optimize?tables='.$table['Name'])}">优化表</a>&nbsp;
                                <a class="ajax-get no-refresh"
                                   href="{:url('repair?tables='.$table['Name'])}">修复表</a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
    </div>
    <!-- /.content-wrapper -->
    {include file="public/footer"/}


</div>
<!-- ./wrapper -->
{include file="public/js"/}

<script type="text/javascript">
    $('#backup-btn').click(function () {
        var _this = $(this);
        console.log(_this);
        var url = _this.data('url');
        if (_this.hasClass('delete-all')) {   //批量处理
            var id = '';
            var str = '';
            var table_box = _this.closest('.box-header').next('.box-body').find(".table tr td input[name='id[]']");
            $(table_box).each(function () {
                if (true == $(this).is(':checked')) {
                    str += $(this).val() + ",";
                }
            });
            if (str.substr(str.length - 1) == ',') {
                id = str.substr(0, str.length - 1);
            }
        } else {                              //单条处理
            var id = _this.data('id') || '';
        }

        $.ajax({
            type: "post",
            url: url,
            dataType: 'json',
            data: {id: id},
            success: function (data) {
                if (data.code === 1) {
                    layer.msg(data.msg, {icon: 6});
                } else {
                    alert('555');
                }
            }
        });
    });
</script>

</body>
</html>
